package com.detrum.costomview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.detrum.base.R;
import com.detrum.bean.ViewPagerItem;
import com.detrum.utils.LogUtils;

/**
 * Created by abc on 2017/7/18.
 */

public class MyViewPagerItem extends RelativeLayout {
    private Context context;
    private View view;
    private TextView name,info;
    private ImageView image;
    public MyViewPagerItem(Context context) {
        super(context);
        this.context=context;
        view = LayoutInflater.from(context).inflate(R.layout.myviewpageritem,this,true);
        initView(view);
    }

    private void initView(View view) {
        name = view.findViewById(R.id.device_name);
        info = view.findViewById(R.id.device_info);
        image = view.findViewById(R.id.image);
    }

    public MyViewPagerItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        view = LayoutInflater.from(context).inflate(R.layout.myviewpageritem,this,true);
        initView(view);
    }

    public void setData(ViewPagerItem item){
        name.setText(item.getName());
        if(item.getMsg()!=null&&item.getMsg().length()!=0){
            info.setText(item.getMsg().split(".2018")[0]);
        }
        if(item.getName().contains("IWT")){
            image.setImageResource(R.mipmap.mslogo);
        }else if(item.getName().contains("DCAM")){
            image.setImageResource(R.mipmap.sport);
        }else{
            image.setImageResource(item.getImage());
        }
    }
}
